package com.googlecode.mylyn.core.util;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * Test for {@link GoogleCodeUtils#extractProjectId(String)}.
 */
@RunWith(Parameterized.class)
public class ExtractProjectIdTest {
    
    private final String projectUrl;
    
    private final String expected;

    public ExtractProjectIdTest(String projectUrl, String expected) {
        this.projectUrl = projectUrl;
        this.expected = expected;
    }
    
    @Parameters
    public static Collection<String[]> data() {
      return Arrays.asList(
          new String[]{"http://code.google.com/p/googlecode-mylyn-connector/", "googlecode-mylyn-connector"},
          new String[]{"http://code.google.com/p/googlecode-mylyn-connector", "googlecode-mylyn-connector"},
          new String[]{"http://code.google.com/p//", null},
          new String[]{"https://code.google.com/p/googlecode-mylyn-connector/", "googlecode-mylyn-connector"},
          new String[]{"https://code.google.com/p/googlecode-mylyn-connector", "googlecode-mylyn-connector"},
          new String[]{"https://code.google.com/p//", null},
          new String[]{"http://code.google.com/a/eclipselabs.org/p/workspacemechanic/", "workspacemechanic"},
          new String[]{"http://code.google.com/a/eclipselabs.org/p/workspacemechanic", "workspacemechanic"},
          new String[]{"http://code.google.com/a/eclipselabs.org/p//", null},
          new String[]{"https://code.google.com/a/eclipselabs.org/p/workspacemechanic/", "workspacemechanic"},
          new String[]{"https://code.google.com/a/eclipselabs.org/p/workspacemechanic", "workspacemechanic"},
          new String[]{"https://code.google.com/a/eclipselabs.org/p//", null}
          );
    }
    
    @Test
    public void extractProjectId() {
        assertEquals(this.expected, GoogleCodeUtils.extractProjectId(this.projectUrl));
    }

}
